import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-03-23
 * Time: 14:26
 */
public class test1 {
    /**
     * 128  最长连续序列
     */

    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int num:nums){
            set.add(num);
        }
        int longest = 0;
        for(int i:set){
            if(!set.contains(i-1)){
                int currentNum = i;
                int currentSize = 1;
                while(set.contains(currentNum+1)){
                    currentNum+=1;
                    currentSize+=1;
                }
                // 更新结果
                longest = Math.max(longest,currentSize);
            }
        }
        return longest;
    }
}
